/**********************************************************************
 * Project : WoWGuildRoster (http://www.codeplex.com/WowGuildRoster/)
 * Module  : DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider
 **********************************************************************
 * 
 * 
 * 
 **********************************************************************
 * License : All code is subject to licensing terms per the Microsoft
 *   Permissive License (Ms-PL) v1.1. For full license information,
 *   refer to the packaged license.txt file.
 **********************************************************************
 * Revision History:
 * -----------------
 * 2007-08-20 -- Cliff Simpkins: Initial Version
 * 2007-09-02 -- Cliff Simpkins: Added the DNN User Drop-Down sproc
 * 2007-11-07 -- Cliff Simpkins: Removed DD duplicate value for DNN users
 **********************************************************************
 */
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using DotNetNuke.Framework.Providers;
using DotNetWarcraft.Common;
using DotNetWarcraft.WoWGuildRoster.Business;
using Microsoft.ApplicationBlocks.Data;


namespace DotNetWarcraft.WoWGuildRoster.Data {
  public class WGR_DnnSqlDataProvider : SqlDataProvider {
    protected ProviderConfiguration _providerConfiguration = ProviderConfiguration.GetProviderConfiguration(providerType);

    protected new static void CreateProvider() {
      objProvider = new WGR_DnnSqlDataProvider();
    }
    public new static WGR_DnnSqlDataProvider Instance() {
      return (WGR_DnnSqlDataProvider)objProvider;
    }

    #region Constructors
    static WGR_DnnSqlDataProvider() {
      CreateProvider();
    }
    public WGR_DnnSqlDataProvider() : base() {
      Provider objProviderConfig = ((Provider)_providerConfiguration.Providers[_providerConfiguration.DefaultProvider]);
      if (objProviderConfig.Attributes["connectionStringName"] != "" && System.Configuration.ConfigurationManager.AppSettings[objProviderConfig.Attributes["connectionStringName"]] != "") {
        this.ConnectionString = System.Configuration.ConfigurationManager.AppSettings[objProviderConfig.Attributes["connectionStringName"]];
      } else {
        this.ConnectionString = objProviderConfig.Attributes["connectionString"];
      }
      _providerPath = objProviderConfig.Attributes["providerPath"];
      _objectQualifier = objProviderConfig.Attributes["objectQualifier"];
      if (_objectQualifier != "" & _objectQualifier.EndsWith("_") == false) {
        _objectQualifier += "_";
      }
      _databaseOwner = objProviderConfig.Attributes["databaseOwner"];
      if (_databaseOwner != "" & _databaseOwner.EndsWith(".") == false) {
        _databaseOwner += ".";
      }

    }
    #endregion

    #region WoWGuildRoster Methods - Roster Modules
    public override DataSet GetRostersDS() {
      DataSet _ds = new DataSet();

      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }
        _ds = SqlHelper.ExecuteDataset(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_GetRosterData");

        if (_ds.Tables.Count <= 0) {
          //No tables returned? - WTF?
          throw new ApplicationException("DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider.GetRoster - No Tables Returned");
        } else {
          //If there is work to do, we do it here

        }
      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e)).WriteExceptionToDB();
      }

      return _ds;

    }

    public List<GuildRosterModule> GetRosterModulesByModule(int ModuleId, int PortalID) {

      List<GuildRosterModule> _rostMods = new List<GuildRosterModule>();
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }
        DataSet _ds = SqlHelper.ExecuteDataset(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_GetRosterModules_ByModule", ModuleId, PortalID);

        if (_ds.Tables.Count <= 0) {
          //No tables returned? - WTF?
          throw new ApplicationException("DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider.GetRosterModulesByModule(" + ModuleId.ToString() + ", " + PortalID.ToString() + ") - No Tables Returned");
        } else if (_ds.Tables[0].Rows.Count <= 0) {
          //No rows were returned; no rosters to process
        } else {
          //Okay, let's get to work - we have a table and rosterModules to read

          foreach (DataRow _dr in _ds.Tables[0].Rows) {
            GuildRosterModule _rostMod = new GuildRosterModule(_dr);
            _rostMods.Add(_rostMod);
          }
        }

      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e)).WriteExceptionToDB();
      }
      return _rostMods;
    }
    public List<GuildRosterModule> GetRosterModulesForSettings(int ModuleId, int PortalID) {

      List<GuildRosterModule> _rostMods = new List<GuildRosterModule>();
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }
        DataSet _ds = SqlHelper.ExecuteDataset(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_GetRosterModules_ForSettings", ModuleId, PortalID);

        if (_ds.Tables.Count <= 0) {
          //No tables returned? - WTF?
          throw new ApplicationException("DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider.GetRosterModulesForSettings(" + ModuleId.ToString() + ", " + PortalID.ToString() + ") - No Tables Returned");
        } else if (_ds.Tables[0].Rows.Count <= 0) {
          //No rows were returned; no rosters to process
        } else {
          //Okay, let's get to work - we have a table and rosterModules to read

          foreach (DataRow _dr in _ds.Tables[0].Rows) {
            GuildRosterModule _rostMod = new GuildRosterModule(_dr);
            _rostMods.Add(_rostMod);
          }
        }

      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e)).WriteExceptionToDB();
      }
      return _rostMods;
    }
    public List<GuildRosterModule> GetRosterModulesByRoster(int RosterId) {

      List<GuildRosterModule> _rostMods = new List<GuildRosterModule>();
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }
        DataSet _ds = SqlHelper.ExecuteDataset(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_GetRosterModules_ByRoster", RosterId);

        if (_ds.Tables.Count <= 0) {
          //No tables returned? - WTF?
          throw new ApplicationException("DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider.GetRosterModulesByRoster(" + RosterId.ToString() + ") - No Tables Returned");
        } else if (_ds.Tables[0].Rows.Count <= 0) {
          //No rows were returned; no rosters to process
        } else {
          //Okay, let's get to work - we have a table and rosterModules to read

          foreach (DataRow _dr in _ds.Tables[0].Rows) {
            GuildRosterModule _rostMod = new GuildRosterModule(_dr);
            _rostMods.Add(_rostMod);
          }
        }

      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e)).WriteExceptionToDB();
      }
      return _rostMods;
    }
    public bool AddRosterModuleEntry(GuildRosterModule objGuildRosterModule) {
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }
        int update = SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_AddRosterModule",
          objGuildRosterModule.Module_ID,
          objGuildRosterModule.Portal_ID,
          objGuildRosterModule.Roster_ID,
          SqlDataUtils.ValidateDbValue(objGuildRosterModule.Can_Load_LUA));

        if (update > 0) {
          return true;
        } else {
          return false;
        }

      } catch (Exception e) {
        (new Business.Exceptions.GuildRosterError(e, -1, objGuildRosterModule.Roster_ID, "DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider.AddRosterModuleEntry(" + objGuildRosterModule.Roster_ID + ")")).WriteExceptionToDB();
        return false;
      }
    }
    public bool DeleteRosterModulesByModule(int ModuleId, int PortalId) {
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }
        int update = SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_DeleteRosterModule_ByModule",
          ModuleId, PortalId);
        if (update > 0) {
          return true;
        } else {
          return false;
        }
      } catch (Exception e) {
        (new Business.Exceptions.GuildRosterError(e, -1, -1, "DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider.DeleteRosterModulesByModule(" + ModuleId + ", " + PortalId + ")")).WriteExceptionToDB();
        return false;
      }
    }
    public bool DeleteRosterModulesByIDs(int ModuleId, int PortalID, int RosterId) {
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }
        int update = SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_DeleteRosterModule_ByIDs",
          ModuleId, PortalID, RosterId);
        if (update > 0) {
          return true;
        } else {
          return false;
        }
      } catch (Exception e) {
        (new Business.Exceptions.GuildRosterError(e, -1, RosterId, "DotNetWarcraft.WoWGuildRoster.Data.DeleteRosterModulesByIDs(" + ModuleId + ", " + PortalID + ", " + RosterId + ")")).WriteExceptionToDB();
        return false;
      }
    }
    public bool DeleteRosterModulesByRoster(int RosterId) {
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }
        int update = SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_DeleteRosterModule_ByRoster",
          RosterId);
        if (update > 0) {
          return true;
        } else {
          return false;
        }
      } catch (Exception e) {
        (new Business.Exceptions.GuildRosterError(e, -1, -1, "DotNetWarcraft.WoWGuildRoster.Data.DeleteRosterModulesByRoster(" + RosterId + ")")).WriteExceptionToDB();
        return false;
      }
    }
    #endregion
    #region WoWGuildRoster Methods - Char Users
    public List<CharEntryUser> GetCharUsersByUser(int UserId, int PortalID) {

      List<CharEntryUser> _charUsers = new List<CharEntryUser>();
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }
        DataSet _ds = SqlHelper.ExecuteDataset(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_GetCharUsers_ByUser", UserId, PortalID);

        if (_ds.Tables.Count <= 0) {
          //No tables returned? - WTF?
          throw new ApplicationException("DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider.GetCharUsersByUser(" + UserId.ToString() + ", " + PortalID.ToString() + ") - No Tables Returned");
        } else if (_ds.Tables[0].Rows.Count <= 0) {
          //No rows were returned; no rosters to process
        } else {
          //Okay, let's get to work - we have a table and entries to read

          foreach (DataRow _dr in _ds.Tables[0].Rows) {
            CharEntryUser _entry = new CharEntryUser(_dr);
            _charUsers.Add(_entry);
          }
        }

      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e, "DotNetWarcraft.WoWGuildRoster.Data.GetCharUsersByUser(" + UserId.ToString() + ", " + PortalID.ToString() + ")")).WriteExceptionToDB();
      }
      return _charUsers;
    }
    public List<CharEntryUser> GetCharUsersByCharEntry(int CharId) {

      List<CharEntryUser> _charUsers = new List<CharEntryUser>();
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }
        DataSet _ds = SqlHelper.ExecuteDataset(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_GetCharUsers_ByChar", CharId);

        if (_ds.Tables.Count <= 0) {
          //No tables returned? - WTF?
          throw new ApplicationException("DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider.GetCharUsersByCharEntry(" + CharId.ToString() + ") - No Tables Returned");
        } else if (_ds.Tables[0].Rows.Count <= 0) {
          //No rows were returned; no rosters to process
        } else {
          //Okay, let's get to work - we have a table and entries to read

          foreach (DataRow _dr in _ds.Tables[0].Rows) {
            CharEntryUser _entry = new CharEntryUser(_dr);
            _charUsers.Add(_entry);
          }
        }

      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e, "DotNetWarcraft.WoWGuildRoster.Data.GetCharUsersByCharEntry(" + CharId.ToString() + ")")).WriteExceptionToDB();
      }
      return _charUsers;
    }
    public bool AddCharUserEntry(CharEntryUser objCharEntryUser) {
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }
        int update = SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_AddCharUser",
          objCharEntryUser.UserID,
          objCharEntryUser.PortalID,
          objCharEntryUser.CharID);

        if (update > 0) {
          return true;
        } else {
          return false;
        }

      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e, "DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider.AddCharUserEntry(" + objCharEntryUser.UserID.ToString() + ", " + objCharEntryUser.PortalID.ToString() + ", " + objCharEntryUser.CharID.ToString() + ")")).WriteExceptionToDB();
        return false;
      }
    }
    public bool DeleteCharUserEntriesByUser(int UserId, int PortalId) {
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }
        int update = SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_DeleteCharUsers_ByUser",
          UserId, PortalId);
        if (update > 0) {
          return true;
        } else {
          return false;
        }
      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e, "DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider.DeleteCharUserEntriesByUser(" + UserId.ToString() + ", " + PortalId.ToString() + ")")).WriteExceptionToDB();
        return false;
      }
    }
    public bool DeleteCharUserEntriesByIDs(int UserId, int PortalID, int CharEntryId) {
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }
        int update = SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_DeleteCharUsers_ByIDs",
          UserId, PortalID, CharEntryId);
        if (update > 0) {
          return true;
        } else {
          return false;
        }
      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e, "DotNetWarcraft.WoWGuildRoster.Data.DeleteCharUserEntriesByIDs(" + UserId.ToString() + ", " + PortalID.ToString() + ", " + CharEntryId.ToString() + ")")).WriteExceptionToDB();
        return false;
      }
    }
    public bool DeleteCharUserEntriesByCharEntry(int CharEntryId) {
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }
        int update = SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_DeleteCharUsers_ByChar",
          CharEntryId);
        if (update > 0) {
          return true;
        } else {
          return false;
        }
      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e, "DotNetWarcraft.WoWGuildRoster.Data.DeleteCharUserEntriesByCharEntry(" + CharEntryId.ToString() + ")")).WriteExceptionToDB();
        return false;
      }
    }
    public bool DeleteCharUserEntriesByCharEntry(int CharEntryId, int PortalId) {
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }
        int update = SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_DeleteCharUsers_ByCharAndPortal",
          CharEntryId, PortalId);
        if (update > 0) {
          return true;
        } else {
          return false;
        }
      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e, "DotNetWarcraft.WoWGuildRoster.Data.DeleteCharUserEntriesByCharEntry(" + CharEntryId.ToString() + ", " + PortalId.ToString() + ")")).WriteExceptionToDB();
        return false;
      }
    }
    #endregion


    #region WoWGuildRoster Methods - Char Entries
    public List<GuildEntry> GetCharEntriesByClass(int moduleID, String className, bool mainsOnly) {
      List<GuildEntry> _entries = new List<GuildEntry>();
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }

        DataSet _ds = SqlHelper.ExecuteDataset(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_GetCharEntries_ByCharClass",
          moduleID, className, (mainsOnly ? 1 : 0));

        if (_ds.Tables.Count <= 0) {
          //No tables returned? - WTF?
          throw new ApplicationException(this.GetType().ToString() + ".GetCharEntriesByClass (" + moduleID.ToString() + ", " + className + ") - No Tables Returned");
        } else if (_ds.Tables[0].Rows.Count <= 0) {
          //No rows were returned; no rosters to process
        } else {
          //Okay, let's get to work - we have a table and rosters to read

          foreach (DataRow _dr in _ds.Tables[0].Rows) {
            GuildEntry _entry = new GuildEntry(_dr);
            _entries.Add(_entry);
          }
        }

      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e)).WriteExceptionToDB();
      }

      return _entries;
    }
    public List<GuildEntry> GetCharEntriesByProfession(int moduleID, String profName, bool mainsOnly) {
      List<GuildEntry> _entries = new List<GuildEntry>();
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }

        DataSet _ds = SqlHelper.ExecuteDataset(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_GetCharEntries_ByCharProf",
          moduleID, profName, (mainsOnly ? 1 : 0));

        if (_ds.Tables.Count <= 0) {
          //No tables returned? - WTF?
          throw new ApplicationException("DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider.GetCharEntriesByProfession (" + moduleID.ToString() + ", " + profName + ") - No Tables Returned");
        } else if (_ds.Tables[0].Rows.Count <= 0) {
          //No rows were returned; no rosters to process
        } else {
          //Okay, let's get to work - we have a table and rosters to read

          foreach (DataRow _dr in _ds.Tables[0].Rows) {
            GuildEntry _entry = new GuildEntry(_dr);
            _entries.Add(_entry);
          }
        }

      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e)).WriteExceptionToDB();
      }

      return _entries;
    }
    public List<GuildEntry> GetCharEntriesByLevel(int moduleID, int LevelMax, int LevelMin, bool mainsOnly) {
      List<GuildEntry> _entries = new List<GuildEntry>();
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }

        DataSet _ds = SqlHelper.ExecuteDataset(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_GetCharEntries_ByLevel",
          moduleID, LevelMax, LevelMin, (mainsOnly ? 1 : 0));

        if (_ds.Tables.Count <= 0) {
          //No tables returned? - WTF?
          throw new ApplicationException("DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider.GetCharEntriesByLevel (" + moduleID.ToString() + ", " + LevelMax.ToString() + ", " + LevelMin.ToString() + ") - No Tables Returned");
        } else if (_ds.Tables[0].Rows.Count <= 0) {
          //No rows were returned; no rosters to process
        } else {
          //Okay, let's get to work - we have a table and rosters to read

          foreach (DataRow _dr in _ds.Tables[0].Rows) {
            GuildEntry _entry = new GuildEntry(_dr);
            _entries.Add(_entry);
          }
        }

      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e)).WriteExceptionToDB();
      }

      return _entries;
    }
    #endregion
    #region WoWGuildRoster Methods - Char Entry Stats
    public List<QuickStatListItem> GetEntryStatsLIs_ByGuildRank(int moduleID, int guildRank, bool mainsOnly) {
      List<QuickStatListItem> _stats = new List<QuickStatListItem>();
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }
        DataSet _ds = SqlHelper.ExecuteDataset(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_GetCharEntryStats_ByGuildRank", moduleID, guildRank, (mainsOnly ? 1 : 0));

        if (_ds.Tables.Count <= 0) {
          //No tables returned? - WTF?
          throw new ApplicationException("DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider.GetEntryStatsLIs_ByGuildRank(" + moduleID.ToString() + ", " + guildRank.ToString() + ") - No Tables Returned");
        } else if (_ds.Tables[0].Rows.Count <= 0) {
          //No rows were returned; no rosters to process
        } else {
          //Okay, let's get to work - we have a table and rows to read

          foreach (DataRow _dr in _ds.Tables[0].Rows) {
            QuickStatListItem _entryStat = new QuickStatListItem(_dr);
            _stats.Add(_entryStat);
          }
        }
        
      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e)).WriteExceptionToDB();
      }

      return _stats;
    }
    public List<QuickStatListItem> GetEntryStatsLIs_ByStatEntryAndType(int moduleID, String statEntry, WarcraftStatTypes statTypeEnum, bool mainsOnly) {
      return GetEntryStatsLIs_ByStatEntryAndType(moduleID, statEntry, WGRConstants.WowStatType_Int(statTypeEnum), mainsOnly);
    }
    public List<QuickStatListItem> GetEntryStatsLIs_ByStatEntryAndType(int moduleID, String statEntry, int statTypeID, bool mainsOnly) {
      List<QuickStatListItem> _stats = new List<QuickStatListItem>();
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }
        DataSet _ds = SqlHelper.ExecuteDataset(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_GetCharEntryStats_ByStatEntryAndType", moduleID, statEntry, statTypeID, (mainsOnly ? 1 : 0));

        if (_ds.Tables.Count <= 0) {
          //No tables returned? - WTF?
          throw new ApplicationException("DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider.GetEntryStatsLIs_ByStatEntryAndType(" + moduleID.ToString() + ", " + statEntry + ", " + statTypeID.ToString() + ") - No Tables Returned");
        } else if (_ds.Tables[0].Rows.Count <= 0) {
          //No rows were returned; no rosters to process
        } else {
          //Okay, let's get to work - we have a table and rosters to read

          foreach (DataRow _dr in _ds.Tables[0].Rows) {
            QuickStatListItem _entryStat = new QuickStatListItem(_dr);
            _stats.Add(_entryStat);
          }
        }

      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e)).WriteExceptionToDB();
      }

      return _stats;
    }
    #endregion
    #region WoWGuildRoster Methods - Drop Down Vals
    public List<DropDownVal> GetDropDowns_DnnUsers(int portalID) {
      List<DropDownVal> _ddVals = new List<DropDownVal>();
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }

        DataSet _ds = SqlHelper.ExecuteDataset(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_DropDownVals_DnnUsers", portalID);

        if (_ds.Tables.Count <= 0) {
          //No tables returned? - WTF?
          throw new ApplicationException("DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider.GetDropDowns_DnnUsers - No Tables Returned");
        } else if (_ds.Tables[0].Rows.Count <= 0) {
          //No rows were returned; no values to process
        } else {
          //Okay, let's get to work - we have a table and values to read

          foreach (DataRow _dr in _ds.Tables[0].Rows) {

            DropDownVal _newDDval = new DropDownVal();
            _newDDval.Key = SqlDataUtils.RetrieveDbString(_dr["UserId"]);
            _newDDval.Value = SqlDataUtils.RetrieveDbString(_dr["username"]) + " (" +
              SqlDataUtils.RetrieveDbString(_dr["FirstName"]) + " " +
              SqlDataUtils.RetrieveDbString(_dr["LastName"]) + ")";

            _ddVals.Add(_newDDval);

            //_ddVals.Add(new DropDownVal(_dr));
          }
        }

      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e)).WriteExceptionToDB();
      }

      return _ddVals;
    }
    public List<DropDownVal> GetDropDowns_DnnUsers_Partial(int portalID, string userName, int count) {
      List<DropDownVal> _ddVals = new List<DropDownVal>();
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }

        DataSet _ds = SqlHelper.ExecuteDataset(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_DropDownVals_DnnUsers_Partial", portalID, userName + "%", count);

        if (_ds.Tables.Count <= 0) {
          //No tables returned? - WTF?
          throw new ApplicationException("DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider.GetDropDowns_DnnUsers_Partial - No Tables Returned");
        } else if (_ds.Tables[0].Rows.Count <= 0) {
          //No rows were returned; no values to process
        } else {
          //Okay, let's get to work - we have a table and values to read

          foreach (DataRow _dr in _ds.Tables[0].Rows) {

            DropDownVal _newDDval = new DropDownVal();
            _newDDval.Key = SqlDataUtils.RetrieveDbString(_dr["UserId"]);
            _newDDval.Value = SqlDataUtils.RetrieveDbString(_dr["username"]);

            _ddVals.Add(_newDDval);

            //_ddVals.Add(new DropDownVal(_dr));
          }
        }

      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e)).WriteExceptionToDB();
      }

      return _ddVals;
    }

    public List<DropDownVal> GetDropDowns_MainChars(int moduleID) {
      List<DropDownVal> _ddVals = new List<DropDownVal>();
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }

        DataSet _ds = SqlHelper.ExecuteDataset(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_DropDownVals_MainChars", moduleID);

        if (_ds.Tables.Count <= 0) {
          //No tables returned? - WTF?
          throw new ApplicationException("DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider.GetDropDowns_MainChars - No Tables Returned");
        } else if (_ds.Tables[0].Rows.Count <= 0) {
          //No rows were returned; no values to process
        } else {
          //Okay, let's get to work - we have a table and values to read

          foreach (DataRow _dr in _ds.Tables[0].Rows) {

            DropDownVal _newDDval = new DropDownVal();
            _newDDval.Key = SqlDataUtils.RetrieveDbString(_dr["char_id"]);
            _newDDval.Value = SqlDataUtils.RetrieveDbString(_dr["char_name"]) + " (" +
              SqlDataUtils.RetrieveDbString(_dr["char_class"]) + ", level " +
              SqlDataUtils.RetrieveDbString(_dr["char_lvl"]) + ")";

            _ddVals.Add(_newDDval);
          }
        }

      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e)).WriteExceptionToDB();
      }

      return _ddVals;
    }
    public List<DropDownVal> GetDropDowns_MainChars_Partial(int moduleID, String charName, int count) {
      List<DropDownVal> _ddVals = new List<DropDownVal>();
      try {
        if (this.ConnectionString == null) {
          throw new WoWGuildRoster.Business.Exceptions.NoConnectStringValueSpecified();
        }

        DataSet _ds = SqlHelper.ExecuteDataset(ConnectionString, DatabaseOwner + ObjectQualifier + "DNW_WGRDNN_DropDownVals_MainChars_Partial", moduleID, charName + "%", count);

        if (_ds.Tables.Count <= 0) {
          //No tables returned? - WTF?
          throw new ApplicationException("DotNetWarcraft.WoWGuildRoster.Data.WGR_DnnSqlDataProvider.GetDropDowns_MainChars_Partial - No Tables Returned");
        } else if (_ds.Tables[0].Rows.Count <= 0) {
          //No rows were returned; no values to process
        } else {
          //Okay, let's get to work - we have a table and values to read

          foreach (DataRow _dr in _ds.Tables[0].Rows) {

            DropDownVal _newDDval = new DropDownVal();
            _newDDval.Key = SqlDataUtils.RetrieveDbString(_dr["char_id"]);
            _newDDval.Value = SqlDataUtils.RetrieveDbString(_dr["char_name"]);

            _ddVals.Add(_newDDval);
          }
        }

      } catch (Exception e) {
        (new Business.Exceptions.WGRGeneralError(e)).WriteExceptionToDB();
      }

      return _ddVals;
    }
    #endregion
  }
}
